local skel = fk.CreateSkill {
  name = "emo__zhiming",
}

Fk:loadTranslationTable{
  ["emo__zhiming"] = "织命",
  [":emo__zhiming"] = "每当你受到1点伤害后，你可以亮出牌堆顶牌，然后可以按之颜色：红色当【乐不思蜀】，黑色当【兵粮寸断】置于一名角色的判定区。",

  ["#emo__zhiming-choose"] = "织命：你可以将此牌当【%arg】置于一名角色判定区",
}

skel:addEffect(fk.Damaged, {
  anim_type = "control",
  trigger_times = function (self, event, target, player, data)
    return data.damage
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cid = room:getNCards(1)[1]
    room:moveCardTo(cid, Card.Processing, nil, fk.ReasonJustMove, skel.name, nil, true, player)
    local color = Fk:getCardById(cid).color
    if not player.dead and color ~= Card.NoColor and room:getCardArea(cid) == Card.Processing then
      local name = color == Card.Red and "indulgence" or "supply_shortage"
      local trick = Fk:cloneCard(name)
      trick:addSubcard(cid)
      trick.skillName = skel.name
      local targets = table.filter(room.alive_players, function (p)
        return not p:isProhibitedTarget(trick)
      end)
      if #targets > 0 then
        local tos = room:askToChoosePlayers(player, {
          min_num = 1, max_num = 1, targets = targets, skill_name = skel.name, cancelable = true,
          prompt = "#emo__zhiming-choose:::"..name,
        })
        if #tos > 0 then
          local to = tos[1]
          to:addVirtualEquip(trick)
          room:moveCardTo(trick, Player.Judge, to, fk.ReasonJustMove, skel.name, nil, true, player)
        end
      end
    end
    room:cleanProcessingArea({cid}, skel.name)
  end,
})

return skel
